//
//  TMCommityBarView.m
//  国学商家管理
//
//  Created by Tao Li on 2018/7/6.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "TMCommityBarView.h"

@implementation TMCommityBarView
-(void)awakeFromNib{
    [super awakeFromNib];
    [self displayGestures];
    //[self displayNumLabel];
}
- (void)displayNumLabel{
    UILabel *bview = [[UILabel alloc]init];
    bview.layer.cornerRadius = 5;
    bview.clipsToBounds = YES;
    bview.backgroundColor = [UIColor redColor];
    CGRect tabFram = self.frame;
    float percentX = (1+0.6)/4;
    CGFloat x = ceilf(percentX*tabFram.size.width);
    CGFloat y = ceilf(0.1*tabFram.size.height);
    bview.frame = CGRectMake(x, y, 10, 10);
    [self addSubview:bview];
    [self bringSubviewToFront:bview];
}
- (void)displayGestures{
    //客服
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(customerServiceViewTap:)];
    [self.customerServiceView addGestureRecognizer:tap];
    //购物车
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(shoppingCarViewTap:)];
    [self.shoppingCarView addGestureRecognizer:tap1];
    //加入购物车
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addShopViewTap:)];
    [self.addShopView addGestureRecognizer:tap2];
    //购买
    UITapGestureRecognizer *tap3 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(purcuseViewTap:)];
    [self.purcuseView addGestureRecognizer:tap3];
}
- (void)customerServiceViewTap:(UITapGestureRecognizer *)res{
    if (self.block) {
        self.block(TapViewTypeCustomerService);
    }
}
- (void)shoppingCarViewTap:(UITapGestureRecognizer *)res{
    if (self.block) {
        self.block(TapViewTypeShoppingCar);
    }
}
- (void)addShopViewTap:(UITapGestureRecognizer *)res{
    if (self.carBlock) {
        self.carBlock();
    }
//    NSInteger cars = self.carBlock();
//    self.shoppingCarNumLabel.text = [NSString stringWithFormat:@"%ld", (long)cars];
//    [self layoutIfNeeded];
}
- (void)purcuseViewTap:(UITapGestureRecognizer *)res{
    if (self.block) {
        self.block(TapViewTypePurcuse);
    }
}
@end
